package com.uni.service.impl;

import com.alibaba.fastjson.JSON;
import com.uni.dao.AreaMapper;
import com.uni.dao.CityMapper;
import com.uni.dao.ProvinceMapper;
import com.uni.pojo.*;
import com.uni.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Author:      Unirithe/Mr.Chao
 * CSDN:        https://blog.csdn.net/Unirithe
 * CreatedTime:  2022/2/7 15:41
 **/
@Service
public class AddressServiceImpl implements AddressService {
    @Autowired
    ProvinceMapper provinceMapper;
    @Autowired
    CityMapper cityMapper;
    @Autowired
    AreaMapper areaMapper;
    @Override
    public List<Province> getAllProvinces() {
        return provinceMapper.selectByExample(new ProvinceExample());
    }

    @Override
    public List<City> getCitiesByProvCode(String provCode) {
        CityExample cityExample = new CityExample() {{
            createCriteria().andProvincecodeEqualTo(provCode);
        }};
        return cityMapper.selectByExample(cityExample);
    }

    @Override
    public List<Area> getAreasByCityCode(String cityCode) {
        AreaExample areaExample = new AreaExample(){{
            createCriteria().andCitycodeEqualTo(cityCode);
        }};
        return areaMapper.selectByExample(areaExample);
    }
}
